package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements Ioperation {

    @Override
    public void work(BookList bookList) {
        System.out.println("归还书籍");

        int current = bookList.getNum();

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要归还的书名");
        String name = scanner.nextLine();

        for (int i = 0; i < current; i++) {
            Book book = bookList.getBooks(i);
            if (book.getName().equals(name)) {
                if (book.isIsborrowed()) {
                    book.setIsborrowed(false);
                    System.out.println("归还成功");
                    return;
                } else {
                    System.out.println("书已存在");
                    return;
                }
            }
        }
        System.out.println("没找到要归还的书名");
    }
}